package queue;

public class LinkedListQueue<E> implements Queue<E> {


    private class Node{
        public E e;
        public Node next;

        public Node(E e,Node next){
            this.e = e;
            this.next = next;
        }

        public Node(E e){
            this(e,null);
        }

        public Node(){
            this(null,null);
        }

        @Override
        public String toString() {
            return e.toString();
        }
    }


    private Node head;  //链表头
    private Node tail;  //链表尾
    private int size;

    public LinkedListQueue(){
        head = null;
        tail = null;
        size = 0;

    }




    //入队,需要从链表尾开始
    @Override
    public void enqueue(E e) {
        if(tail == null){
            tail = new Node(e);
            head = tail;
        }else {
            tail.next = new Node(e);
            tail = tail.next;
        }
        size++;
    }

    //出队，从链表头开始
    @Override
    public E dequeue() {
        if(isEmpty()){
            //队列为null，不允许出队
        }

        Node retNode = head;
        head = head.next;
        retNode.next = null;
        if(head == null){
            tail = null;
        }

        size--;
        return retNode.e;
    }

    @Override
    public E getFront() {
        return null;
    }

    @Override
    public int getSize() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }
}
